﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ThanhvienDAL: DAL.BaseDAL
    {
        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Thanhvien");
        }

        /// <summary>
        /// Select User
        /// </summary>
        /// <param name="_user"> _user</param>
        /// <returns> data table </returns>
        public DataTable Select(string _user)
        {
            try
            {
                string sql = @"Select * From TAIKHOAN Where Ten = '{0}' collate Latin1_General_CS_AS ";
                sql = string.Format(sql, _user);
                return ExecuteQuery(sql);
            }
            catch { return null; }
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            var sql = @"select taikhoan,matkhau,vaitro,hoten from TAIKHOAN where Taikhoan = '{0}' collate Latin1_General_CS_AS";
            sql = String.Format(sql, key);
            var tbl = ExecuteQuery(sql);
            try
            {
                if (tbl.Rows.Count > 0)
                {
                    var usr = new Entities.Thanhvien();
                    usr.taikhoan = tbl.Rows[0]["TAIKHOAN"] + "";
                    usr.matkhau = tbl.Rows[0]["MATKHAU"] + "";
                    usr.hoten = tbl.Rows[0]["HOTEN"] + "";
                    usr.vaitro = Convert.ToInt32(tbl.Rows[0]["VAITRO"]);
                    return usr;
                }
                else return null;
            }
            catch { return null; }
        }

       
        
    }
}
